package com.lm.scau.dyb.Receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

import com.lm.scau.dyb.activity.base.BaseActivity;
import com.lm.scau.dyb.utils.FlagHelper;

/**
 * Created by Administrator on 2016/8/20.
 */
public class NetworkChangeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        State wifiState = null;
        State mobileState = null;
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
        if (wifiState != null && mobileState != null && State.CONNECTED != wifiState && State.CONNECTED == mobileState) {
            // 手机网络连接成功
            FlagHelper.NETWORK = FlagHelper.NETWORK_MOBILE;
           // ((BaseActivity)context).showToast("正在使用手机网络");
        } else if (wifiState != null && mobileState != null && State.CONNECTED != wifiState && State.CONNECTED != mobileState) {
            // 手机没有任何的网络
            FlagHelper.NETWORK = null;
            ((BaseActivity)context).showToast("没有任何网络");
        } else if (wifiState != null && State.CONNECTED == wifiState) {
            // 无线网络连接成功
            FlagHelper.NETWORK = FlagHelper.NETWORK_WIFI;
         //   ((BaseActivity)context).showToast("无线网络连接成功");
        }
    }
}
